#include<iostream>
#include<cmath>
#define MAXSIZE 1000
using namespace std;
bool isPrime(int n)
{
	if(n < 2)
		return false;
	for(int i = 2; i <= sqrt(n); ++ i )
	{
		if(n % i == 0)
			return false;
	}
	return true;
}
int change(int n,int d)
{
	int i = 0,sum = 0,temp[MAXSIZE] = {0};
	while(n)
	{
		temp[i++]=n%d;
		n /= d;
	}
	for(int j = 0; j < i ; ++ j)
	{
		sum = sum * d + temp[j];
	}
	return sum;
}
int main()
{
	int n,d,temp;
	while(cin>>n && n > 0)
	{
		cin >> d;
		if(!isPrime(n))
		{
			cout << "No" << endl;
		}
		else
		{
			temp = change(n,d);
			if(!isPrime(temp))
			{
				cout << "No" << endl;
			}
			else
			{
				cout << "Yes" << endl;
			}
		}
	}
	return 0;
}